import Vue from 'vue'
import App from './App.vue'
import Find from "@/view/Find"
import My from "@/view/My"
import Part from "@/view/Part"
import VueRouter from "vue-router"
import NotFound from "@/view/NotFound.vue";
import Recommend from "@/view/Second/Recommend.vue";
import Ranking from "@/view/Second/Ranking.vue";
import SongList from "@/view/Second/SongList.vue";
Vue.config.productionTip = false

Vue.use(VueRouter)


const routes=[
    {
        path:"/",
        redirect:"/find"
    },
    {
        path: "/find",
        name:"/find",
        component: Find,
        children: [
            {
                path: "",//二级子路由的默认显示
                component: SongList
            },
            {
                path: "recommend",
                component: Recommend
            },
            {
                path: "ranking",
                component: Ranking
            },
            {
                path: "songlist",
                component: SongList
            }
        ]
    },
    {
        path: "/my",
        name:"/my",
        component: My
    },
    {
        path: "/part/:username",
        component: Part
    }, {
        path: "/part",
        name:"/part",
        component: Part
    },{
    path: "*",
        component:NotFound
    }
]
const router = new VueRouter({
    mode:"history",
    routes,// routes是固定key(传入规则数组)
    // mode: "history" // 默认不写是"hash"
})

const isLogin=false
router.beforeEach((to,from,next)=>{
    if (to.path=="/my"&&isLogin===false){
        alert("请登录")
        next(false)

    }else{
        next( )
    }

})
new Vue({
    render: h => h(App), router
}).$mount('#app')
